<?php namespace Home\Controller;
use Hdphp\Controller\Controller;

class ListController extends Controller{
	public function index(){
		//点击分类
		$cid=Q('get.cid',0,'intval');
		$arcModel=new \Common\Model\Arc;
		$cateModel=new \Common\Model\Cate;
		$arcTagModel=new \Common\Model\ArcTag;
		$tagModel=new \Common\Model\Tag;
		//点击分类
		if($cid=Q('get.cid',0,'intval')){
			//名字
			$name='分类';
			//分类的名字
			$value=$cateModel->where("cid={$cid}")->pluck('cname');
			//获得当前点击分类所有的子集对应
			$cids=$cateModel->getSon($cateModel->get(),$cid);
			$cids[]=$cid;
			//查询文章表对应的总数
			$total=$arcModel
					->where('category_cid IN (' .implode(',',$cids).') and is_recycle=0')
					->count();
			//查询分类对应的文章
			$data=$arcModel->join('category','cid','=','category_cid')
						  ->where('category_cid IN (' .implode(',',$cids).') and is_recycle=0')
						  ->get();
				foreach($data as $k=>$v){
					$data[$k]['tag']=$arcTagModel
					      ->join('tag','tag_tid','=','tid')
						  ->where("article_aid={$v['aid']}")
						  ->get();
				}
		}
		//点击标签
		if($tid=Q('get.tid',0,'intval')){
			$name='标签';
			$value=$tagModel->where("tid={$tid}")->pluck('tname');
			//统计有多少的子集
			$total=$tagModel
					->join('article_tag','tag_tid','=','tid')
					->join('article','aid','=','article_aid')
					->where("tid={$tid} and is_recycle=0")
					->count();
//			//标签下面的所有的文章
			$data=$arcTagModel 
				->join('article','aid','=','article_aid')
				->join('category','cid','=','category_cid')
				->where("tag_tid={$tid} and is_recycle=0")
				->get();
			foreach($data as $k=>$v){
				$data[$k]['tag'] = $arcTagModel
							->join('tag','tag_tid','=','tid')
							->where("article_aid={$v['aid']}")
							->get();				
			}
		}
		define('NAME', $name);
		define('VALUE', $value);
		define('TOTAL', $total);
		//获取分类对应的文章
		View::with('total',$total);
		View::with('name',$name);
		View::with('value',$value);
		View::with('data',$data);
		View::make();
	}
	
}


 ?>
 











































